﻿
Dcqtech_Form_Controls.CheckBox = $.extend({}, Dcqtech_Form_Controls.Default);

Dcqtech_Form_Controls.CheckBox.setValue = function (id, value, fieldInfo, $root, isFirstSet) {
    $root.find("[dcqtech_id='" + id + "'] input[type='checkbox']").each(function () { this.checked = false; });
    if (!value) return;

    $root.find("[dcqtech_data='" + id + "']").val(value);
    var vls = value.split("**");
    for (var i = 0; i < vls.length; i++) {
        $root.find("[dcqtech_id='" + id + "'] input[type='checkbox'][value='" + vls[i] + "']").prop("checked", true);
    }
};

Dcqtech_Form_Controls.CheckBox.setDefaultValue = function (id, $root, fieldInfo) {
    var value = fieldInfo.defaultValue;
    if (!value) return;
    value = template.render(value,ServerParam);
    Dcqtech_Form_Controls.CheckBox.setValue(id, value, fieldInfo, $root);
    $("[dcqtech_id='" + id + "']").css("height","auto");
    $("[dcqtech_id='" + id + "'] input[type='checkbox']").parent("label").css("line-height","44px");
};

Dcqtech_Form_Controls.CheckBox.setReadonly = function (id, isReadOnly) {
    if (typeof isReadOnly != "boolean") {
        isReadOnly = isReadOnly == "1";
    }
    $("[dcqtech_id='" + id + "'] input[type='checkbox']").prop("disabled", isReadOnly);
};

Dcqtech_Form_Controls.CheckBox.setEditEvent = function (id, wdInfo, $root) {
    var $control = $root.find("[dcqtech_id='" + id + "'] ");
    if ($control.attr("dcq_inited") == "1") return;
    $control.attr("dcq_inited", "1");
    $control.on("click", "input[type='checkbox']", function () {
        console.info(this);
        var ids = $root.find("[dcqtech_id='" + id + "'] input[type='checkbox']:checked").map(function () { return this.value }).get();
        console.info(ids);
        $root.find("[dcqtech_data='" + id + "']").val(ids.join("**"));
    });
};
